/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-10
 * Time: 6:00
 */
public class Test {
    public static void main(String[] args) {
        //iter
        char ch = 'a';
        System.out.println(Integer.toBinaryString(ch));
        int i = 2147483647;
        float a = 0.1f;
        float b = 0.5f;
        System.out.println(Math.round(a));
        System.out.println(Math.round(b));
        System.out.println("-i:" + " " +Integer.toBinaryString(-i));
        System.out.println("~i:" + " " +Integer.toBinaryString(i));
        System.out.println("~i:" + " " +Integer.toBinaryString(~i));
        System.out.println(Integer.toBinaryString(2147483647));
        System.out.println(Integer.toBinaryString(-2147483647));
    }
    public static int binaryGap(int n) {
        String s = Integer.toBinaryString(n);
        int pre = 0;
        int cur = 1;
        int max = 0;
        while(cur < s.length()){
            if(s.charAt(pre) == '1' && s.charAt(cur) == '1'){
                max = Math.max(max,cur-pre);
                pre++;
                cur++;
            }
            if(cur < s.length() && s.charAt(pre) == '0'){
                pre++;
            }
            if(cur < s.length() && s.charAt(cur) == '0'){
                cur++;
            }
        }
        return max;
    }
    public static void main1(String[] args) {
        System.out.println(binaryGap(5));
    }
}
